#ifndef EVENT_EVENTLOOPTHREADPOOL_H_
#define EVENT_EVENTLOOPTHREADPOOL_H_
#include <mono/event/event_loop_thread.h>
#include <mono/event/event_loop.h>
#include <vector>
#include <functional>
#include <string>

namespace mono {

class EventLoopThread;

class EventLoopThreadPool {
public:
    typedef std::function<void(EventLoopPtr)> ThreadInitCallback;

    EventLoopThreadPool(EventLoopPtr &baseLoop, const std::string &name ="");
    ~EventLoopThreadPool();
    void setThreadNum(int numThreads) { _numThreads = numThreads; }
    void start(const ThreadInitCallback& cb = ThreadInitCallback());
    void stop();

    // valid after calling start()
    /// round-robin
    EventLoopPtr getNextLoop();

    /// with the same hash code, it will always return the same EventLoop
    EventLoopPtr getLoopForHash(size_t hashCode);

    std::vector<EventLoopPtr> getAllLoops();

    bool started() const
    { return _started; }

   private:

    EventLoopPtr                     _baseLoop;
    bool                             _started;
    int                              _numThreads;
    int                              _next;
    std::vector<EventLoopThreadPtr>  _threads;
    std::vector<EventLoopPtr>        _loops;
    std::string                      _name;
};

}
#endif